package com.eboss2.sbs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.eboss2.sbs.R;

import java.util.ArrayList;
import java.util.BitSet;

public class ChooseCashAmtAdapter extends BaseAdapter{

	private ArrayList<String> values = new ArrayList<String>();
	private BitSet marks = new BitSet();
	private LayoutInflater mInflater;//得到一个LayoutInfalter对象用来导入布局

	public ChooseCashAmtAdapter(Context in, ArrayList<String> values, BitSet marks){
		this.mInflater = LayoutInflater.from(in);
		this.values = values;
		this.marks = marks;
	}
	@Override
	public int getCount() {
		if(values==null||values.size()==0)return 0;
		return values.size();
	}
	@Override
	public Object getItem(int position) {return position;}
	@Override
	public long getItemId(int position) {return position;}
	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		ViewHolder holder;
		if(convertView == null){                                         //初始化ViewHolder对
			convertView = mInflater.inflate(R.layout.listitem_option_cash, null);
			holder = new ViewHolder();
			holder.option_button = (TextView)convertView.findViewById(R.id.option_button);
			convertView.setTag(holder);//绑定ViewHolder对象 
		}
		else {holder = (ViewHolder)convertView.getTag();}  //取出ViewHolder对
		holder.option_button.setText(values.get(position));
		holder.option_button.setSelected(marks.get(position));
		return convertView;
	}

	public void setDatas(ArrayList<String> datas) {
		this.values.clear();
		this.values.addAll(datas);
		notifyDataSetChanged();
	}
	
	public final class ViewHolder{  
		public TextView option_button;
	}
	
}